const http = require('http')
const url = require('url')

const jsonFn = obj => JSON.stringify(obj)


http.createServer((req, res) => {
  console.log(req.headers)
  let user = {
    id: 1,
    name: '张三'
  }
  // res.setHeader('Access-Control-Allow-Origin', '*')
  res.setHeader('Access-Control-Allow-Origin', req.headers.origin)
  // 允许cookie跨域
  res.setHeader('Access-Control-Allow-Credentials', 'true')
  // 服务器返回指定的响应头信息给客户端
  res.setHeader('content-type', 'application/json;charset=utf-8')
  res.end(jsonFn(user))
}).listen(3000)


